<template>
  <div class="contract-add-view">
    <div class="page-header">
      <h2>添加合同</h2>
    </div>

    <el-card class="form-card">
      <el-form 
        ref="contractForm" 
        :model="contractForm" 
        :rules="contractRules" 
        label-width="120px"
        v-loading="submitLoading"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="客户企业" prop="customer_id">
              <el-autocomplete
                v-model="companyName"
                :fetch-suggestions="searchCustomers"
                placeholder="请输入企业名称进行搜索"
                style="width: 100%;"
                @select="handleCustomerSelect"
                clearable
                :trigger-on-focus="false"
                :debounce="500"
                popper-class="customer-search-dropdown"
              >
                <template slot-scope="{ item }">
                  <div class="customer-option">
                    <div class="company-name">{{ item.customer.Name }}</div>
                    <div class="customer-info">
                      <span v-if="item.customer.UserName">负责人: {{ item.customer.UserName }}</span>
                      <span v-if="item.customer.Address">地址: {{ item.customer.Address }}</span>
                      <span v-if="item.customer.UserTel">电话: {{ item.customer.UserTel }}</span>
                    </div>
                  </div>
                </template>
              </el-autocomplete>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同编号" prop="contract_name">
              <el-input 
                v-model="contractForm.contract_name" 
                placeholder=""
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="合同金额" prop="cost">
              <el-input 
                v-model="contractForm.cost" 
                placeholder="请输入合同金额"
                type="number"
                step="0.01"
                class="amount-input"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款状态" prop="payment_status">
              <el-select v-model="contractForm.payment_status" placeholder="请选择付款状态" style="width: 100%;">
                <el-option label="未付款" :value="0"></el-option>
                <el-option label="已付款" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否需要施工" prop="is_construction">
              <el-select v-model="contractForm.is_construction" placeholder="请选择是否需要施工" style="width: 100%;">
                <el-option label="不施工" :value="0"></el-option>
                <el-option label="施工" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <el-form-item label="付款时间" prop="payment_time" v-if="contractForm.payment_status === 1">
              <el-date-picker
                v-model="contractForm.payment_time"
                type="datetime"
                placeholder="请选择付款时间"
                style="width: 100%;"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="预计付款时间" prop="estimated_payment_time" v-if="contractForm.payment_status === 0">
              <el-date-picker
                v-model="contractForm.estimated_payment_time"
                type="datetime"
                placeholder="请选择预计付款时间"
                style="width: 100%;"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="合同图片" prop="img">
              <el-upload
                ref="upload"
                :action="uploadAction"
                :auto-upload="false"
                :on-change="handleFileChange"
                :on-remove="handleFileRemove"
                :file-list="fileList"
                :limit="5"
                accept="image/*"
                list-type="picture-card"
                :before-upload="() => false"
                multiple
              >
                <i class="el-icon-plus"></i>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过100MB，最多可上传5张图片</div>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款凭证" prop="img_payment">
              <el-upload
                ref="paymentUpload"
                :action="uploadAction"
                :auto-upload="false"
                :on-change="handlePaymentFileChange"
                :on-remove="handlePaymentFileRemove"
                :file-list="paymentFileList"
                :limit="5"
                accept="image/*"
                list-type="picture-card"
                :before-upload="() => false"
                multiple
              >
                <i class="el-icon-plus"></i>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过100MB，最多可上传5张图片</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="合同备注" prop="remark">
              <el-input 
                v-model="contractForm.remark" 
                type="textarea" 
                :rows="4"
                placeholder="请输入合同备注"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 收货人信息区域 -->
        <div class="recipient-info-section">
          <div class="recipient-header" @click="toggleRecipientInfo">
            <span class="recipient-title">收货人信息</span>
            <span class="recipient-toggle">【{{ showRecipientInfo ? '点击隐藏' : '点击显示' }}】</span>
          </div>
          
          <div v-if="showRecipientInfo" class="recipient-content">
            <p class="recipient-instruction">收货人信息已自动填写，如需修改请点击下方按钮</p>
            <el-button 
              type="primary" 
              size="small" 
              @click="editRecipientInfo"
              class="recipient-edit-btn"
            >
              点击按钮即可编辑收货人信息
            </el-button>
            
            <el-row :gutter="20" class="recipient-fields">
              <el-col :span="8">
                <el-form-item label="收货人" prop="recipient_name">
                  <el-input 
                    v-model="contractForm.recipient_name" 
                    placeholder="收货人姓名"
                    :disabled="!isEditingRecipient"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="联系电话" prop="recipient_tel">
                  <el-input 
                    v-model="contractForm.recipient_tel" 
                    placeholder="联系电话"
                    :disabled="!isEditingRecipient"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="收货地址" prop="recipient_address">
                  <el-input 
                    v-model="contractForm.recipient_address" 
                    placeholder="收货地址"
                    :disabled="!isEditingRecipient"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
        <el-form-item>
          <el-button type="primary" @click="submitForm" :loading="submitLoading">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
          <el-button @click="goBack">返回</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getContractNumber ,addContract, searchCustomerByCompany } from '@/api/contract';
import { checkToken, handleTokenExpired, checkTokenFromError } from '@/utils/auth';
import request from '@/utils/request';

export default {
  name: 'ContractAddView',
  data() {
    return {
      // 表单数据
      contractForm: {
        customer_id: '',
        contract_name: '',
        remark: '',
        payment_time: '',
        payment_status: 1, // 默认值为1
        cost: '',
        is_construction: 0, // 默认不施工
        estimated_payment_time: '',
        // 收货人信息字段
        recipient_name: '',
        recipient_tel: '',
        recipient_address: ''
      },
      
      // 客户搜索相关
      companyName: '',
      
      // 收货人信息显示控制
      showRecipientInfo: false,
      isEditingRecipient: false,
      
      // 表单验证规则
      contractRules: {
        customer_id: [
          { required: true, message: '请选择客户', trigger: 'change' }
        ],
        contract_name: [
          { required: true, message: '请输入合同名称', trigger: 'blur' }
        ],
        cost: [
          { required: true, message: '请输入合同金额', trigger: 'blur' }
        ],
        payment_status: [
          { required: true, message: '请选择付款状态', trigger: 'change' }
        ],
        is_construction: [
          { required: true, message: '请选择是否需要施工', trigger: 'change' }
        ]
      },
      
      // 文件上传相关
      fileList: [],
      paymentFileList: [], // 付款凭证文件列表
      uploadAction: '#', // 不使用自动上传
      
      // 图片路径数组
      imgUrls: [], // 合同图片路径数组
      paymentImgUrls: [], // 付款凭证图片路径数组
      
      // 提交状态
      submitLoading: false
    }
  },
  mounted(){
      this.getContractNumber();
  },
  methods: {
    async getContractNumber()
    {
        const response = await getContractNumber();
        console.log(response.data.msg);
        this.contractForm.contract_name=response.data.msg
    },
    // 搜索客户
    async searchCustomers(queryString, callback) {
      if (queryString.length < 2) {
        callback([]);
        return;
      }
      
      try {
        // 检查token是否存在
        if (!checkToken()) {
          this.$message.error('登录已过期，请重新登录');
          handleTokenExpired();
          return;
        }
        
        const response = await searchCustomerByCompany(queryString);
        
        if (response.data && response.data.code) {
          const customers = response.data.msg || [];
          const suggestions = customers.map(customer => ({
            value: customer.Name,
            customer: customer
          }));
          callback(suggestions);
        } else {
          callback([]);
        }
      } catch (error) {
        console.error('搜索客户失败:', error);
        if (checkTokenFromError(error)) {
          this.$message.error('登录已过期，请重新登录');
          handleTokenExpired();
        } else {
          this.$message.error('搜索客户失败');
        }
        callback([]);
      }
    },
    
    // 选择客户
    handleCustomerSelect(item) {
      this.contractForm.customer_id = item.customer.CustomerId;
      this.companyName = item.customer.Name;
      
      // 自动填充收货人信息
      this.contractForm.recipient_name = item.customer.UserName || '';
      this.contractForm.recipient_tel = item.customer.UserTel || '';
      this.contractForm.recipient_address = item.customer.Address || '';
      
      // 不自动显示收货人信息区域，让用户手动点击显示
      this.isEditingRecipient = false;
    },
    
    // 切换收货人信息显示/隐藏
    toggleRecipientInfo() {
      this.showRecipientInfo = !this.showRecipientInfo;
    },
    
    // 编辑收货人信息
    editRecipientInfo() {
      this.isEditingRecipient = !this.isEditingRecipient;
    },
    
    // 文件选择改变
    async handleFileChange(file, fileList) {
      console.log('文件对象:', file);
      console.log('文件对象详细信息:', {
        name: file.name,
        size: file.size,
        type: file.type,
        raw: file.raw,
        hasRaw: !!file.raw,
        rawType: file.raw ? typeof file.raw : 'undefined'
      });
      
      // 检查文件对象是否有效
      if (!file || !file.raw) {
        this.$message.error('文件对象无效');
        return;
      }
      
      // 限制文件大小
      const isLt2M = file.size / 1024 / 1024 < 100;
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 100MB!');
        // 移除当前文件
        const index = fileList.findIndex(item => item.uid === file.uid);
        if (index > -1) {
          fileList.splice(index, 1);
        }
        this.fileList = fileList;
        return;
      }
      
      // 限制文件类型 - 添加安全检查
      if (file.type && typeof file.type === 'string') {
        const isImage = file.type.startsWith('image/');
        if (!isImage) {
          this.$message.error('只能上传图片文件!');
          // 移除当前文件
          const index = fileList.findIndex(item => item.uid === file.uid);
          if (index > -1) {
            fileList.splice(index, 1);
          }
          this.fileList = fileList;
          return;
        }
      } else {
        // 如果无法获取文件类型，通过文件扩展名检查
        const fileName = file.name || '';
        const validExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'];
        const hasValidExtension = validExtensions.some(ext => 
          fileName.toLowerCase().endsWith(ext)
        );
        
        if (!hasValidExtension) {
          this.$message.error('只能上传图片文件!');
          // 移除当前文件
          const index = fileList.findIndex(item => item.uid === file.uid);
          if (index > -1) {
            fileList.splice(index, 1);
          }
          this.fileList = fileList;
          return;
        }
      }
      
      // 上传图片到服务器
      const imageUrl = await this.uploadSingleImage(file.raw, 'productcontract');
      if (imageUrl) {
        // 上传成功，添加到路径数组
        this.imgUrls.push(imageUrl);
        console.log('合同图片上传成功:', imageUrl);
        console.log('合同图片路径数组:', this.imgUrls);
        
        // 更新文件对象的url属性，以便删除时能正确识别
        const fileIndex = fileList.findIndex(item => item.uid === file.uid);
        if (fileIndex > -1) {
          fileList[fileIndex].url = imageUrl;
        }
      } else {
        // 上传失败，移除文件
        const index = fileList.findIndex(item => item.uid === file.uid);
        if (index > -1) {
          fileList.splice(index, 1);
        }
      }
      
      this.fileList = fileList;
      console.log('文件列表更新:', this.fileList);
    },
    
    // 文件移除
    handleFileRemove(file, fileList) {
      this.fileList = fileList;
      
      // 从路径数组中移除对应的路径
      if (file.url) {
        const index = this.imgUrls.findIndex(url => url === file.url);
        if (index > -1) {
          this.imgUrls.splice(index, 1);
          console.log('从合同图片数组中移除:', file.url);
          console.log('剩余合同图片数组:', this.imgUrls);
        }
      }
    },
    
    // 付款凭证文件选择改变
    async handlePaymentFileChange(file, fileList) {
      console.log('付款凭证文件对象:', file);
      console.log('付款凭证文件对象详细信息:', {
        name: file.name,
        size: file.size,
        type: file.type,
        raw: file.raw,
        hasRaw: !!file.raw,
        rawType: file.raw ? typeof file.raw : 'undefined'
      });
      
      // 检查文件对象是否有效
      if (!file || !file.raw) {
        this.$message.error('文件对象无效');
        return;
      }
      
      // 限制文件大小
      const isLt2M = file.size / 1024 / 1024 < 100;
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 100MB!');
        // 移除当前文件
        const index = fileList.findIndex(item => item.uid === file.uid);
        if (index > -1) {
          fileList.splice(index, 1);
        }
        this.paymentFileList = fileList;
        return;
      }
      
      // 限制文件类型 - 添加安全检查
      if (file.type && typeof file.type === 'string') {
        const isImage = file.type.startsWith('image/');
        if (!isImage) {
          this.$message.error('只能上传图片文件!');
          // 移除当前文件
          const index = fileList.findIndex(item => item.uid === file.uid);
          if (index > -1) {
            fileList.splice(index, 1);
          }
          this.paymentFileList = fileList;
          return;
        }
      } else {
        // 如果无法获取文件类型，通过文件扩展名检查
        const fileName = file.name || '';
        const validExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'];
        const hasValidExtension = validExtensions.some(ext => 
          fileName.toLowerCase().endsWith(ext)
        );
        if (!hasValidExtension) {
          this.$message.error('只能上传图片文件!');
          // 移除当前文件
          const index = fileList.findIndex(item => item.uid === file.uid);
          if (index > -1) {
            fileList.splice(index, 1);
          }
          this.paymentFileList = fileList;
          return;
        }
      }
      
      // 上传图片到服务器
      const imageUrl = await this.uploadSingleImage(file.raw, 'productcontract');
      if (imageUrl) {
        // 上传成功，添加到路径数组
        this.paymentImgUrls.push(imageUrl);
        console.log('付款凭证图片上传成功:', imageUrl);
        console.log('付款凭证图片路径数组:', this.paymentImgUrls);
        
        // 更新文件对象的url属性，以便删除时能正确识别
        const fileIndex = fileList.findIndex(item => item.uid === file.uid);
        if (fileIndex > -1) {
          fileList[fileIndex].url = imageUrl;
        }
      } else {
        // 上传失败，移除文件
        const index = fileList.findIndex(item => item.uid === file.uid);
        if (index > -1) {
          fileList.splice(index, 1);
        }
      }
      
      this.paymentFileList = fileList;
      console.log('付款凭证文件列表更新:', this.paymentFileList);
    },
    
    // 付款凭证文件移除
    handlePaymentFileRemove(file, fileList) {
      this.paymentFileList = fileList;
      
      // 从路径数组中移除对应的路径
      if (file.url) {
        const index = this.paymentImgUrls.findIndex(url => url === file.url);
        if (index > -1) {
          this.paymentImgUrls.splice(index, 1);
          console.log('从付款凭证图片数组中移除:', file.url);
          console.log('剩余付款凭证图片数组:', this.paymentImgUrls);
        }
      }
    },
    
    // 单图片上传方法
    async uploadSingleImage(file, type = 'productcontract') {
      try {
        // 检查token是否存在
        if (!checkToken()) {
          this.$message.error('登录已过期，请重新登录');
          handleTokenExpired();
          return null;
        }
        
        const token = localStorage.getItem('token');
        const formData = new FormData();
        formData.append('img', file);
        formData.append('type', type);
        formData.append('token', token);
        
        const response = await request({
          method: 'POST',
          data: formData,
          url: 'index.php/api/newfile.Contract/uploadImg',
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        });
        
        if (response.data && response.data.status === 'ok') {
          return response.data.data; // 返回图片URL
        } else {
          this.$message.error(response.data.data || '图片上传失败');
          return null;
        }
      } catch (error) {
        console.error('图片上传失败:', error);
        if (checkTokenFromError(error)) {
          this.$message.error('登录已过期，请重新登录');
          handleTokenExpired();
        } else {
          this.$message.error('图片上传失败');
        }
        return null;
      }
    },
    
    // 提交表单
    async submitForm() {
      try {
        // 检查token是否存在
        if (!checkToken()) {
          this.$message.error('登录已过期，请重新登录');
          handleTokenExpired();
          return;
        }
        
        // 检查是否选择了客户
        if (!this.contractForm.customer_id) {
          this.$message.error('请选择客户');
          return;
        }
        
        // 验证表单
        const valid = await this.$refs.contractForm.validate();
        if (!valid) {
          return;
        }
        
        // 检查付款时间（如果付款状态为已付款或部分付款，则付款时间为必填）
        if ((this.contractForm.payment_status === 1 || this.contractForm.payment_status === 2) && !this.contractForm.payment_time) {
          this.$message.error('已付款或部分付款状态下，付款时间为必填项');
          return;
        }
        
        this.submitLoading = true;
        
        // 准备提交数据
        const submitData = { ...this.contractForm };
        
        // 添加图片路径（如果上传了的话）
        if (this.imgUrls.length > 0) {
          console.log('合同图片路径数组:', this.imgUrls);
          submitData.img = this.imgUrls;
        }
        
        // 处理付款时间格式
        if (submitData.payment_time) {
          // 将日期字符串转换为时间戳
          const timestamp = Math.floor(new Date(submitData.payment_time).getTime() / 1000);
          // 检查时间戳是否在合理范围内（1970年到2038年）
          if (timestamp > 0 && timestamp < 2147483647) {
            submitData.payment_time = timestamp;
          } else {
            this.$message.error('付款时间超出有效范围');
            return;
          }
        } else {
          // 如果没有付款时间，设置为null
          submitData.payment_time = null;
        }
        
        // 处理金额格式
        if (submitData.cost) {
          submitData.cost = parseFloat(submitData.cost);
        }
        
        // 处理付款状态
        if (submitData.payment_status !== '') {
          submitData.payment_status = parseInt(submitData.payment_status);
        } else {
          submitData.payment_status = 1; // 默认为1
        }
        
        // 处理施工状态
        if (submitData.is_construction !== '') {
          submitData.is_construction = parseInt(submitData.is_construction);
        } else {
          submitData.is_construction = 0; // 默认为0
        }
        
        // 处理预计付款时间格式
        if (submitData.estimated_payment_time) {
          // 将日期字符串转换为时间戳
          const estimatedTimestamp = Math.floor(new Date(submitData.estimated_payment_time).getTime() / 1000);
          // 检查时间戳是否在合理范围内（1970年到2038年）
          if (estimatedTimestamp > 0 && estimatedTimestamp < 2147483647) {
            submitData.estimated_payment_time = estimatedTimestamp;
          } else {
            this.$message.error('预计付款时间超出有效范围');
            return;
          }
        } else {
          // 如果没有预计付款时间，设置为null
          submitData.estimated_payment_time = null;
        }
        
        // 添加付款凭证图片路径（如果上传了的话）
        if (this.paymentImgUrls.length > 0) {
          console.log('付款凭证图片路径数组:', this.paymentImgUrls);
          submitData.img_payment = this.paymentImgUrls;
        }
        
        console.log('准备提交的数据:', submitData);
        const response = await addContract(submitData);
        
        if (response.data && response.data.code) {
          this.$message.success('合同添加成功');
          this.resetForm();
          // 跳转到合同列表页面
          this.$router.push('/contract-management');
        } else {
          this.$message.error(response.data.msg || '合同添加失败');
        }
      } catch (error) {
        console.error('合同添加失败:', error);
        if (checkTokenFromError(error)) {
          // Token无效或过期
          this.$message.error('登录已过期，请重新登录');
          handleTokenExpired();
        } else {
          // 其他错误
          this.$message.error('合同添加失败');
        }
      } finally {
        this.submitLoading = false;
      }
    },
    
    // 重置表单
    resetForm() {
      this.$refs.contractForm.resetFields();
      this.companyName = '';
      this.fileList = [];
      this.paymentFileList = [];
      this.imgUrls = [];
      this.paymentImgUrls = [];
      this.$refs.upload.clearFiles();
      this.$refs.paymentUpload.clearFiles();
      
      // 重置收货人信息相关状态
      this.showRecipientInfo = false;
      this.isEditingRecipient = false;
      this.contractForm.recipient_name = '';
      this.contractForm.recipient_tel = '';
      this.contractForm.recipient_address = '';
      
      // 重置新添加的字段
      this.contractForm.is_construction = 0;
      this.contractForm.estimated_payment_time = '';
    },
    
    // 返回上一页
    goBack() {
      this.$router.go(-1);
    }
  }
}
</script>

<style scoped>
.contract-add-view {
  padding: 20px;
  background-color: #fff;
  min-height: calc(100vh - 60px);
  box-sizing: border-box;
}

.page-header {
  margin-bottom: 20px;
}

.page-header h2 {
  margin: 0;
  color: #303133;
  font-size: 24px;
  font-weight: 500;
}

.form-card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.el-form {
  padding: 20px 0;
}

/* 收货人信息区域样式 */
.recipient-info-section {
  margin: 20px 0;
  border: 1px solid #e4e7ed;
  border-radius: 6px;
  background-color: #fafafa;
}

.recipient-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background-color: #409eff;
  color: white;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  transition: background-color 0.3s;
}

.recipient-header:hover {
  background-color: #337ecc;
}

.recipient-title {
  font-size: 16px;
  font-weight: 500;
}

.recipient-toggle {
  font-size: 12px;
  opacity: 0.9;
}

.recipient-content {
  padding: 20px;
  
}

.recipient-instruction {
  color: #606266;
  margin-bottom: 15px;
  font-size: 14px;
}

.recipient-edit-btn {
  margin-bottom: 20px;
}

.recipient-fields {
  margin-top: 15px;
}

.el-upload__tip {
  font-size: 12px;
  color: #606266;
  margin-top: 7px;
}

.el-upload--picture-card {
  width: 148px;
  height: 148px;
  line-height: 146px;
}

.el-upload-list--picture-card .el-upload-list__item {
  width: 148px;
  height: 148px;
}
::v-deep .el-input__inner {
  background-color: white !important;
}
/* 客户搜索选项样式 */
.customer-option {
  padding: 8px 0;
  width: 100%;
}

.customer-option .company-name {
  font-weight: 500;
  color: #303133;
  margin-bottom: 6px;
  font-size: 14px;
}

.customer-option .customer-info {
  font-size: 12px;
  color: #909399;
  line-height: 1.5;
}

.customer-option .customer-info span {
  display: block;
  margin-bottom: 3px;
}

.customer-option .customer-info span:last-child {
  margin-bottom: 0;
}

/* 调整搜索下拉框宽度 */
:deep(.el-autocomplete-suggestion) {
  min-width: 400px !important;
  max-width: 600px !important;
}

:deep(.el-autocomplete-suggestion__list) {
  max-height: 300px;
  overflow-y: auto;
}

:deep(.el-autocomplete-suggestion__list li) {
  padding: 8px 12px;
  line-height: 1.4;
}

/* 合同金额输入框样式 */
.amount-input {
  background-color: #fff;
}

.amount-input .el-input__inner {
  background-color: #fff;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.amount-input .el-input__inner:focus {
  border-color: #409eff;
  outline: none;
}

.amount-input .el-input-group__prepend {
  background-color: #f5f7fa;
  border: 1px solid #dcdfe6;
  border-right: none;
  color: #606266;
  font-weight: 500;
}

.amount-input .el-input-group__append {
  background-color: #f5f7fa;
  border: 1px solid #dcdfe6;
  border-left: none;
}

.amount-input:hover .el-input__inner {
  border-color: #c0c4cc;
}

.amount-input .el-input__inner::placeholder {
  color: #c0c4cc;
}
</style>

<style>
/* 全局样式：调整搜索下拉框宽度 */
.customer-search-dropdown {
  min-width: 400px !important;
  max-width: 600px !important;
}

.customer-search-dropdown .el-autocomplete-suggestion__list {
  max-height: 300px;
  overflow-y: auto;
}

.customer-search-dropdown .el-autocomplete-suggestion__list li {
  padding: 8px 12px;
  line-height: 1.4;
}
</style> 